package com.zmn.oms.dubbo.impl.zmn.third.daojia58;

import org.apache.dubbo.config.annotation.Service;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.oms.dubbo.interfaces.zmn.third.daojia58.DaoJia58RemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.third.dj58.DaoJia58Consts;
import com.zmn.oms.third.dj58.dto.api.DaoJia58Response;
import com.zmn.oms.third.dj58.service.DaoJia58Service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotBlank;
import java.util.Objects;

/**
 * 到家58对外服务
 * @author: LuJia
 * @version: v1.0
 * @since: 2020/03/21 13:10
 **/
@Service(loadbalance = "roundrobin", timeout = 10000,  version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class DaoJia58RemoteServiceImpl implements DaoJia58RemoteService {

    @Autowired
    DaoJia58Service daoJia58Service;

    @Override
    public ResponseDTO<String> sendRequestTo58DaoJia(@NotBlank String pathRequest, @NotBlank String paramJson) {

        DaoJia58Response res = daoJia58Service.sendRequestTo58DaoJia(pathRequest, paramJson);
        if (Objects.isNull(res) || !Objects.equals(res.getCode(), DaoJia58Consts.DAOJIA58_RETURN_CODE_SUCCESS)) {
            return ResponseDTO.fail(res.getCode(), StringUtils.defaultString(res.getMessage(), "请求失败查询oms-dubbo日志排查问题"));
        }

        return ResponseDTO.success(res.getData(), res.getMessage());
    }
}
